package com.cssw.fyzb.busi.api.appeal;

import com.cssw.fyzb.busi.api.task.CollecTask;
import com.cssw.fyzb.core.model.vo.appeal.AppealTypeVo;
import com.cssw.fyzb.busi.service.appeal.AppealService;
import com.cssw.fyzb.core.model.dodb.AppealType;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author
 */
@Function(description = "申述类型")
@Component
public class ListAppealType implements Action {

    private final static Logger logger = LoggerFactory.getLogger(CollecTask.class);

    @Autowired
    private AppealService appealService;

    @Override
    public Response execute(Request request) throws Exception {
        try {
            List<AppealType> appealTypes = appealService.listAppealType();
            List<AppealTypeVo> vos = new ArrayList<>();
            AppealTypeVo vo = null;
            for (AppealType a : appealTypes) {
                vo = new AppealTypeVo();
                vo.setAppealType(a.getAppealType());
                vo.setAppealTypeName(a.getAppealTypeName());
                vo.setRemark(a.getRemark());
                vos.add(vo);
            }
            return Response.success().put("data", vos);
        } catch (Exception e) {
            logger.debug("", e);
            return Response.fail("操作失败");
        }
    }
}
